/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package mas.server;

import mas.shared.Request;
import mas.shared.ResponseCommand;
import mas.shared.impl.ResponseImpl;
import mas.shared.utils.RequestHandler;

/**
 *
 * @author liese
 */
public class CommandHandler extends Thread
{
    private RequestHandler rh;
    
    public CommandHandler(RequestHandler rh)
    {
        super("CommandHandler");
        this.rh = rh;
    }
    
    @Override
    public void run()
    {
        try
        {
            Request request = rh.readRequest();
            switch (request.getCommand())
            {
                case requestTask: handOutTask(); break;
                case provideSolution: takeSolution(); break;
            }

            Thread.sleep(10000);
            
            rh.sendResponse(new ResponseImpl(ResponseCommand.okay));
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
    }
    
    public static void handOutTask()
    {
        System.err.println(">>>> Handing out task.");
    }
    
    public static void takeSolution()
    {
        System.err.println("<<<< Taking solution.");
    }
}
